import {getDictList} from "@/api/system/dict";
// 将祖先code设置给每个节点
function setDataAncestorCode (dataList, ancestor) {
  dataList.forEach(item => {
    let currentAncestor = ancestor || item
    item.ancestorCode = currentAncestor.code
    if (item.children) {
      setDataAncestorCode(item.children, currentAncestor)
    }
  })
}
export default {
  // hasCheck: true,
  hasIndex: true,
  request: (params) => {
    return getDictList(params)
  },
  dataParse: (res) => {
    const resData = res.data.data || []
    setDataAncestorCode(resData)
    const data = {
      list: resData,
      total: resData.total
    }
    return data
  },
  columns: [
    {
      prop: 'code',
      label: '字典编号',
    },
    {
      prop: 'dictValue',
      label: '字典名称',
    },
    {
      prop: 'dictKey',
      label: '字典键值',
    },
    {
      prop: 'sort',
      label: '字典排序',
    },
    {
      prop: 'operate',
      label: '操作',
      isSlot: true,
    }
  ]
}